package sysinit

import (
	"github.com/gorilla/mux"
	"net/http"
)
//本课程来自程序员在囧途(www.jtthink.com)咨询群：98514334
//route构建器， build 方法必须要执行
var MyRouter *mux.Router

func init() {
	MyRouter=mux.NewRouter()
}
type RouteBuilder struct {
	route *mux.Route
}
func NewRouteBuilder() *RouteBuilder {
	return &RouteBuilder{route: MyRouter.NewRoute()}
}
//本课程来自程序员在囧途(www.jtthink.com)咨询群：98514334
func(this *RouteBuilder) SetPath(path string ,exact bool ) *RouteBuilder{

	if exact{
		 this.route.Path(path)
	}else{
		 this.route.PathPrefix(path)
	}
   return this
}
//第二个参数是故意的，方便调用时 传入 条件，省的外面写 if else
func(this *RouteBuilder) SetHost(host string, set bool ) *RouteBuilder{
	if set{
		this.route.Host(host)
	}
	 return this
}
func(this *RouteBuilder) Build(handler http.Handler)  {
	 this.route.
		Methods("GET","POST","PUT","DELETE","OPTIONS").
		Handler(handler)
}
//本课程来自程序员在囧途(www.jtthink.com)咨询群：98514334